package com.wlient.springboot_quartz.scheduler;

import org.springframework.stereotype.Component;

import java.util.concurrent.*;

@Component("demoTask")
public class DemoTask {


    public void taskWithParams(String params) {
        System.out.println("执行有参示例任务：" + params);
    }

    public void taskNoParams() {
        System.out.println("执行无参示例任务");
    }

    public void createTaskTemo(String num){
        ExecutorService service = new ThreadPoolExecutor(2, 5,
                100L, TimeUnit.SECONDS, new LinkedBlockingDeque<>(3),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        System.out.println(num);
        try {
            for (int i = 1; i <= 8; i++) {
                int tem = i;
                service.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + "线程处理任务" + tem);
                    try {
                        TimeUnit.SECONDS.sleep(2);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                });
            }
        } finally {
            service.shutdown();
        }
    }

}
